package com.xatl.simulated.util;

import com.xatl.simulated.response.MyDeviceData;
import com.xatl.simulated.response.Values;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author pandi
 * @create 2020-11-08 0:44
 */
public class NumberUtil {

    //产生随机数并保留小数点后两位返回
    public static double randomToTwo(){
        Random random = new Random();
        double i = random.nextDouble()*100;
        DecimalFormat df = new DecimalFormat(".00");
        String s =df.format(i);
        double j = Double.parseDouble(s);
        return j;
    }

    //产生随机数据
    public static List<MyDeviceData> random(){
        ArrayList<MyDeviceData> list = new ArrayList<>();
        MyDeviceData myDeviceData = new MyDeviceData();
        myDeviceData.setTs(new Date().getTime());
        Values values = new Values();
        values.setHumidity(NumberUtil.randomToTwo());
        values.setTemperature(NumberUtil.randomToTwo());
        myDeviceData.setValues(values);
        list.add(myDeviceData);
        return list;
    }



}
